


/*
'===============================================================================
'  TuanHuy.BL.GalleriesManagerBase
'===============================================================================
*/
#region Using
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using TuanHuy.BLL;
using TuanHuy.DAL;
using TuanHuy.DAL.EntityClasses;
using TuanHuy.DAL.FactoryClasses;
using TuanHuy.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
#endregion

/*
'===============================================================================
'	
'  	
'  	
'  	
'  	
'	
'===============================================================================
*/
namespace TuanHuy.BLL
{
	///<summary>
	/// ModuleName:			Galleries
	/// CreatedBy:					
	/// CreatedDate:				4/8/2014 5:37:37 PM
	/// UpdatedBy:					<unknow>
	/// UpdatedDate:				<unknow>
	/// Description:				No Edit by User
	/// Notes for Update:	
	/// </summary>
	public class GalleriesManagerBase:ManagerBase
	{
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public GalleriesManagerBase()
		{
			// Nothing for now.
		}
		
		/*public override string TableName()
        {
            return "Galleries";
        }*/
		
		public GalleriesEntity Insert(GalleriesEntity _GalleriesEntity)
		{
			return Insert(_GalleriesEntity, "");
		}
		
		public GalleriesEntity Insert(GalleriesEntity _GalleriesEntity, string controlId)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(_GalleriesEntity, true);
				GalleriesFields field = new GalleriesFields();
                //LogEntity(_GalleriesEntity, field, AcInsert, controlId);
			}
			return _GalleriesEntity;
		}

		
		public GalleriesEntity Insert(decimal Id, string Image, string Type, decimal ObjectId)
		{
			GalleriesEntity _GalleriesEntity = new GalleriesEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_GalleriesEntity.Id = Id;
				_GalleriesEntity.Image = Image;
				_GalleriesEntity.Type = Type;
				_GalleriesEntity.ObjectId = ObjectId;
				GalleriesFields field = new GalleriesFields();
                //LogEntity(_GalleriesEntity, field, AcInsert);
				adapter.SaveEntity(_GalleriesEntity, true);
			}
			return _GalleriesEntity;
		}

		
		public bool Update(GalleriesEntity _GalleriesEntity)
        {
            return Update(_GalleriesEntity, "");
        }

		public bool Update(GalleriesEntity _GalleriesEntity, string controlId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(GalleriesFields.Id == _GalleriesEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_GalleriesEntity, filter);
				toReturn = true;
				
				GalleriesFields field = new GalleriesFields();
                //LogEntity(_GalleriesEntity, field, AcUpdate, controlId);
			}
			return toReturn;
		}
		
		public bool Update(GalleriesEntity _GalleriesEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_GalleriesEntity, filter);
				toReturn = true;
				
				GalleriesFields field = new GalleriesFields();
                //LogEntity(_GalleriesEntity, field, AcUpdate);
			}
			return toReturn;
		}

		public bool Update(decimal Id, string Image, string Type, decimal ObjectId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				GalleriesEntity _GalleriesEntity = new GalleriesEntity(Id);
				if (adapter.FetchEntity(_GalleriesEntity))
				{
				
					_GalleriesEntity.Image = Image;
					_GalleriesEntity.Type = Type;
					_GalleriesEntity.ObjectId = ObjectId;
					adapter.SaveEntity(_GalleriesEntity, true);
					toReturn = true;
					
					GalleriesFields field = new GalleriesFields();
					//LogEntity(_GalleriesEntity, field, AcUpdate);
				}
			}
			return toReturn;
		}

		public bool Delete(decimal Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				GalleriesEntity _GalleriesEntity = new GalleriesEntity(Id);
				if (adapter.FetchEntity(_GalleriesEntity))
				{
					adapter.DeleteEntity(_GalleriesEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("GalleriesEntity", null);
			}
		}
		
		
		public int DeleteById(decimal Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("GalleriesEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByImage(string Image)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("GalleriesEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByType(string Type)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Type == Type);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("GalleriesEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByObjectId(decimal ObjectId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.ObjectId == ObjectId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("GalleriesEntity", filter);
			}
			return toReturn;
		}
		

		
		public GalleriesEntity SelectOne(decimal Id)
		{
			GalleriesEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				GalleriesEntity _GalleriesEntity = new GalleriesEntity(Id);
				if (adapter.FetchEntity(_GalleriesEntity))
				{
					toReturn = _GalleriesEntity;
				}
			}
			return toReturn;
		}

		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleriesCollection = new EntityCollection(new GalleriesEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleriesCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection<GalleriesEntity>
		public EntityCollection<GalleriesEntity> SelectAllLST()
		{
			EntityCollection<GalleriesEntity> _GalleriesCollection = new EntityCollection<GalleriesEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleriesCollection, null, 0, null);
			}
			return _GalleriesCollection;
		}
		
		// Return EntityCollection<GalleriesEntity>
		public EntityCollection<GalleriesEntity> SelectAllLST_Paged(int PageNumber, int PageSize)
		{
			EntityCollection<GalleriesEntity> _GalleriesCollection = new EntityCollection<GalleriesEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleriesCollection, null, 0, null, null, PageNumber, PageSize);
			}
			return _GalleriesCollection;
		}


		
		// Return EntityCollection<GalleriesEntity>
		public EntityCollection<GalleriesEntity> SelectByIdLST(decimal Id)
		{
			EntityCollection<GalleriesEntity> _GalleriesCollection = new EntityCollection<GalleriesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleriesCollection, filter, 0, null);
			}
			return _GalleriesCollection;
		}
		
		// Return EntityCollection<GalleriesEntity>
		public EntityCollection<GalleriesEntity> SelectByIdLST_Paged(decimal Id, int PageNumber, int PageSize)
		{
			EntityCollection<GalleriesEntity> _GalleriesCollection = new EntityCollection<GalleriesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleriesCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _GalleriesCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(decimal Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleriesCollection = new EntityCollection(new GalleriesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleriesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT_Paged(decimal Id, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleriesCollection = new EntityCollection(new GalleriesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleriesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}
		
		// Return EntityCollection<GalleriesEntity>
		public EntityCollection<GalleriesEntity> SelectByImageLST(string Image)
		{
			EntityCollection<GalleriesEntity> _GalleriesCollection = new EntityCollection<GalleriesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleriesCollection, filter, 0, null);
			}
			return _GalleriesCollection;
		}
		
		// Return EntityCollection<GalleriesEntity>
		public EntityCollection<GalleriesEntity> SelectByImageLST_Paged(string Image, int PageNumber, int PageSize)
		{
			EntityCollection<GalleriesEntity> _GalleriesCollection = new EntityCollection<GalleriesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleriesCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _GalleriesCollection;
		}
		
		// Return DataTable
		public DataTable SelectByImageRDT(string Image)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleriesCollection = new EntityCollection(new GalleriesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleriesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByImageRDT_Paged(string Image, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleriesCollection = new EntityCollection(new GalleriesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleriesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}
		
		// Return EntityCollection<GalleriesEntity>
		public EntityCollection<GalleriesEntity> SelectByTypeLST(string Type)
		{
			EntityCollection<GalleriesEntity> _GalleriesCollection = new EntityCollection<GalleriesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Type == Type);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleriesCollection, filter, 0, null);
			}
			return _GalleriesCollection;
		}
		
		// Return EntityCollection<GalleriesEntity>
		public EntityCollection<GalleriesEntity> SelectByTypeLST_Paged(string Type, int PageNumber, int PageSize)
		{
			EntityCollection<GalleriesEntity> _GalleriesCollection = new EntityCollection<GalleriesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Type == Type);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleriesCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _GalleriesCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTypeRDT(string Type)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleriesCollection = new EntityCollection(new GalleriesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Type == Type);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleriesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByTypeRDT_Paged(string Type, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleriesCollection = new EntityCollection(new GalleriesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.Type == Type);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleriesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}
		
		// Return EntityCollection<GalleriesEntity>
		public EntityCollection<GalleriesEntity> SelectByObjectIdLST(decimal ObjectId)
		{
			EntityCollection<GalleriesEntity> _GalleriesCollection = new EntityCollection<GalleriesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.ObjectId == ObjectId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleriesCollection, filter, 0, null);
			}
			return _GalleriesCollection;
		}
		
		// Return EntityCollection<GalleriesEntity>
		public EntityCollection<GalleriesEntity> SelectByObjectIdLST_Paged(decimal ObjectId, int PageNumber, int PageSize)
		{
			EntityCollection<GalleriesEntity> _GalleriesCollection = new EntityCollection<GalleriesEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.ObjectId == ObjectId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleriesCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _GalleriesCollection;
		}
		
		// Return DataTable
		public DataTable SelectByObjectIdRDT(decimal ObjectId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleriesCollection = new EntityCollection(new GalleriesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.ObjectId == ObjectId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleriesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByObjectIdRDT_Paged(decimal ObjectId, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleriesCollection = new EntityCollection(new GalleriesEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleriesFields.ObjectId == ObjectId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleriesCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}
			
	}
}
